<?php
/**
 * AdminController.php
 *
 * PHP version 5
 *
 * LICENSE: This source file is subject to version 2.0 of the Apache license
 * that is available through the world-wide-web at the following URI:
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * @category Controller
 * @package  Controller
 * @author   Alex Kopp <koppa@rpi.edu>
 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link     http://http://code.google.com/p/tri-chi/
 */

/**
 * AdminController
 *
 * The controller that manages the administrative features in
 * the GLOrganizer system
 *
 * @category Controller
 * @package  Controller
 * @author   Alex Kopp <koppa@rpi.edu>
 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link     http://http://code.google.com/p/tri-chi/
 */
class AdminController extends Controller
{
    public $layout='//layouts/main';
    /**
     * This is the list of filters we would like to enable for this controller.
     * 
     * We want to limit access to this controller... Thus, including 'accessControl'
     * 
     * @return array action filters
     */
    public function filters()
    {
        return array(
            'accessControl',
        );
    }

    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * 
     * Only authenticated members should be permitted log out
     * Everyone is permitted to log in
     * 
     * @return array access control rules
     */
    public function accessRules()
    {
        return array(
        array('allow',
            'actions'=>array('index'),
            'roles'=>array('admin'),
        ),
        array('deny',
            'users'=>array('*'),
        ),
        );
    }

    /**
     * This is the default 'index' action that is invoked
     * when an action is not explicitly requested by users.
     * 
     * @return void
     */
    public function actionIndex()
    {
        $this->render('index');
    }

    /**
     * This is the action to handle external exceptions.
     * 
     * @return void
     */
    public function actionError()
    {
        if ($error=Yii::app()->errorHandler->error) {
            if (Yii::app()->request->isAjaxRequest) {
                echo $error['message'];
            } else {
                $this->render('error', $error);
            }
        }
    }

}